
<template>
  <div class="tvmPiaoKuanCYTZ">
    <basic-container>
      <avue-crud
        ref="tvmPiaoKuanCYTZ"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :page.sync="page"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="getList"
        @on-load="getList">

        <template slot-scope="scope" slot="conductorPersonNameSearch">
          <el-select v-model="searchForm.conductorPersonName" placeholder="请选择" style="width: 150px" filterable clearable>
            <el-option
              v-for="(item,index) in conductorPersonNames"
              :key="index"
              :label="item.nikename"
              :value="item.nikename">
            </el-option>
          </el-select>
        </template>
<!--        <template slot-scope="scope" slot="search">-->
<!--          <el-form-item label="时间" style="width: 570px">-->
<!--            <div style="width: 500px;display: inline-flex">-->
<!--              <el-date-picker-->
<!--                v-model="searchForm.startTime"-->
<!--                type="date"-->
<!--                placeholder="选择日期"-->
<!--                value-format="yyyy-MM-dd">-->
<!--              </el-date-picker>-->
<!--              ~-->
<!--              <el-date-picker-->
<!--                v-model="searchForm.endTime"-->
<!--                type="date"-->
<!--                placeholder="选择日期"-->
<!--                value-format="yyyy-MM-dd">-->
<!--              </el-date-picker>-->
<!--            </div>-->
<!--          </el-form-item>-->

<!--        </template>-->
        <template slot="search" slot-scope="{row,size}">
          <el-form-item label="差异条件" style="width: 300px" >
            <el-select v-model="searchForm.isDifferenceAmount" placeholder="请选择">
              <el-option label="长款" value="1"></el-option>
              <el-option label="短款" value="2"></el-option>
            </el-select>
          </el-form-item>
        </template>
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button type="text" size="small" plain @click.stop="previewOp(scope.row)">预览</el-button>
          <el-button type="text" size="small"
                     v-if="scope.row.appealStatus==1 && permissionList.openApprove
                     && (scope.row.auditSate == 1 || scope.row.auditSate == 3 || scope.row.auditSate == 6)"
                     plain @click.stop="openAffirm(scope.row)">确认</el-button>
          <el-button type="text" size="small"
                     v-if="permissionList.openApprove && scope.row.appealStatus==6 && scope.row.auditSate==2"
                     plain @click.stop="recallAffirm(scope.row)">撤回确认</el-button>
          <el-button type="text" size="small"
                     v-if="permissionList.openApprove && scope.row.appealStatus==2 && (scope.row.auditSate==3 || scope.row.auditSate==6)"
                     plain @click.stop="recallAppeal(scope.row)">撤回申诉</el-button>
          <el-button type="text" size="small"
                     v-if="(scope.row.auditSate==2 || scope.row.auditSate==3 || scope.row.auditSate==6)
                      && (scope.row.appealStatus==2 || scope.row.appealStatus==6) && permissionList.openApprove"
                     plain @click.stop="subAudit(scope.row)">提交</el-button>
          <el-button type="text" size="small"
                     v-if="permissionList.stationMasterAudit && (scope.row.auditSate==4 || scope.row.auditSate==8)"
                     plain @click.stop="stationMasterAuditOption(scope.row)">审核通过</el-button><!-- 站长审核通过-->
          <el-button type="text" size="small"
                     v-if="permissionList.stationMasterReject && (scope.row.auditSate==4 || scope.row.auditSate==8)"
                     plain @click.stop="stationMasterReject(scope.row)">驳回</el-button><!-- 站长审核驳回-->
          <el-button type="text" size="small"
                     v-if="permissionList.openApprove && (scope.row.appealStatus ==1 || scope.row.appealStatus ==4)
                        && (scope.row.auditSate == 1 || scope.row.auditSate == 3 || scope.row.auditSate == 6)"
                     plain @click.stop="openApprove(scope.row,1)">申诉</el-button>
        </template>
      </avue-crud>
      <approve ref="approve" v-if="dialogVisibleAppealReply"></approve>
      <affirm ref="affirm" v-if="dialogVisibleOpenAffirm"></affirm>
      <open-dialog
        :DialogVisible.sync="stationMasterRejectShow"
        title="站长审核意见"
        width="60%"
      >
        <el-form v-if="stationMasterRejectShow">
          <avue-form
            v-model="stationMasterRejectForm"
            :option="stationMasterRejectOption"></avue-form>
        </el-form>
        <div class="bottom-menu-invalid">
          <el-button type="primary" @click="subForm">保存</el-button>
          <el-button type="primary" @click="stationMasterRejectShow = false" >取消</el-button>
        </div>
      </open-dialog>

      <open-dialog
        :DialogVisible.sync="stationMasterRejectOptionShow"
        title="站长审核意见"
        width="60%"
      >
        <el-form v-if="stationMasterRejectOptionShow">
          <avue-form
            v-model="stationMasterRejectForm"
            :option="stationMasterRejectOption"></avue-form>
        </el-form>
        <div class="bottom-menu-invalid">
          <el-button type="primary" @click="stationMasterAudit">保存</el-button>
          <el-button type="primary" @click="stationMasterRejectOptionShow = false" >取消</el-button>
        </div>
      </open-dialog>
      <prev ref="prev" v-if="dialogVisibleprev"></prev>
    </basic-container>
  </div>

</template>

<script>
import {mapGetters} from 'vuex';
import moment from 'moment';
import approve from './approve';
import affirm from './affirm';
import prev from './prev';

import {stationMasterRejectOption} from "@/const/crud/zhanNeiRYDLCK";
import {
  clearSelect,
  getgetStationCodes,
  getLineCodes, getSysUserToLS, setSearchFiledsEmpty
} from "@/api/subwayRat/commonCheck";
import {getTvmPiaoKuanCYTZOption,
  getSwAuTvmNoticeList,
  affirmSwAuTvmNotice,
  recallAppealSwAuTvmNotice,
  recallTvmNotice,
  subAuditSwAuTvmNotice,
  auditSwAuTvmrNotice} from '@/api/subwayRat/swAuTvm/tvmCYQRTZ'
export default {
  name: 'tvmPiaoKuanCYTZ',
  components:{
    affirm,
    approve,
    prev
  },
  data() {
    return {
      dialogVisibleOpenAffirm:false,
      dialogVisibleAppealReply:false, //申诉回复
      stationMasterRejectShow:false,
      stationMasterRejectOptionShow: false,
      dialogVisibleprev:false,//预览
      option: {},
      listLoading: true,
      lineCodes:[],
      stationCodes:[],
      conductorPersonNames:[],
      selectKeys:[],
      selectKeyVals:[],
      searchForm:{},
      stationMasterRejectForm: {},
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20, // 每页显示多少条,
        isAsc: false// 是否倒序
      },
      param:{
        replyPeriod:"",//回复期限
        appealReply:'',//申诉回复
      },
      list : [],
      stationMasterRejectOption: stationMasterRejectOption
    }
  },
  computed: {
    ...mapGetters(['permissions']),
    permissionList () {
      return {
        stationMasterAudit: this.vaildData(
          this.permissions.tvmPiaoKuanCYTZ_AUDIT_STATION_PASS,
          false
        ),
        stationMasterReject: this.vaildData(
          this.permissions.tvmPiaoKuanCYTZ_AUDIT_STATION_REJECT,
          false
        ),
        openApprove: this.vaildData(
          this.permissions.tvmPiaoKuanCYTZ_edit,
          false
        ),
      };
    },
  },
  watch: {
  },
  created() {
    this.option=getTvmPiaoKuanCYTZOption();
  },
  methods: {
    setSearchFiledsEmpty,
    moment,
    getList() {
      this.listLoading = true;
      Object.assign(this.searchForm,this.page);
      this.searchForm.lineCode=this.$store.getters.userInfo.lineCode;
      this.searchForm.stationCode=this.$store.getters.userInfo.stationCode;
      this.searchForm.sendStatus=2;
      getSwAuTvmNoticeList(this.searchForm).then((response)=>{
        this.list = response.data.data.list;
        this.listLoading = false;
        this.page.total=response.data.data.pageInfo.total;
      });
    },

    openApprove(row,showType){
      this.dialogVisibleAppealReply=true;
      this.$nextTick(()=>{
        this.$refs.approve.dialogVisible=true;
        this.$refs.approve.recallShow(row,showType,this);
      })
    },
    previewOp(row){
      this.dialogVisibleprev=true;
      this.$nextTick(()=>{
        this.$refs.prev.dialogVisible=true;
        this.$refs.prev.recallShow(row,this);
      })
    },
    recallAffirm(row){
      let th=this;
      recallTvmNotice({id:row.id}).then(res=>{
        if(res.data.code==0){
          th.$message.success("操作成功！");
          th.getList();
        }else{
          th.$message.error("操作失败！");
        }
      })
    },
    recallAppeal(row){
      let th=this;
      recallAppealSwAuTvmNotice({ids:row.id}).then(res=>{
        if(res.data.code==0){
          th.$message.success("操作成功！");
          th.getList();
        }else{
          th.$message.error("操作失败！");
        }
      })
    },
    subAudit(row){
      let th=this;
      this.$confirm("是否确认?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(res=>{
        subAuditSwAuTvmNotice({
          id:row.id
        }).then(res=>{
          th.$message.success("操作成功！");
          th.getList();
        }).catch(() => {
          th.$message.error("操作失败！");
        })
      })
    },
    stationMasterAudit(row){
      let th=this;
      if (this.stationMasterRejectForm.auditStationOpinion == null || this.stationMasterRejectForm.auditStationOpinion == '') {
        th.$message.error("请填写审核意见！");
        return false;
      }
      auditSwAuTvmrNotice({
        id:this.stationMasterRejectForm.id,
        auditSate:5,
        auditStationOpinion:this.stationMasterRejectForm.auditStationOpinion
      }).then(res=>{
        th.$message.success("站长审核成功！");
        this.stationMasterRejectOptionShow=false;
        th.getList();
      })
        .catch(() => {
          // th.$message.error("站长审核失败！");
          return false;
        });
    },
    stationMasterReject: function (row){
      // row.$cellEdit = true;
      this.stationMasterRejectShow=true;
      this.stationMasterRejectForm = row;
    },
    stationMasterAuditOption: function (row){
      this.stationMasterRejectOptionShow=true;
      this.stationMasterRejectForm = row;
    },
    subForm(){
      let th=this;
      auditSwAuTvmrNotice({
        id:this.stationMasterRejectForm.id,
        auditSate:6,
        auditStationOpinion:this.stationMasterRejectForm.auditStationOpinion
      }).then(res=>{
        th.$message.success("站长审核成功！");
        this.stationMasterRejectShow=false;
        th.getList();
      })
        .catch(() => {
          // th.$message.error("站长审核失败！");
          return false;
        });
    },

    openAffirm(row){
      this.dialogVisibleOpenAffirm=true;
      this.$nextTick(()=>{
        this.$refs.affirm.dialogVisible=true;
        this.$refs.affirm.recallShow(row,this);
      })
    },

    selectionChange(list){
      this.selectKeys=list;
      this.selectKeyVals=[];
      for(let i=0;i<list.length;i++){
        this.selectKeyVals.push(list[i].id);
      }
    },
    handleFilter(params, done) {
      Object.assign(this.searchForm,params);
      this.getList()
      done()
    },
    changeLine(v){ //改变线路时
      getgetStationCodes(v).then(res=>{
        this.stationCodes=res;
      })
    },
    changeStation(){
      this.conductorPersonNames=[];
      // getPersonRole({roleCode:'SPY',stationCode:v}).then((res)=>{
      //   this.conductorPersonNames=this.conductorPersonNames.concat(res.data.data);
      // });
      // getPersonRole({roleCode:'KYZBY',stationCode:v}).then((res)=>{
      //   this.conductorPersonNames=res.data.data;
      // });
      // getPersonRole({roleCode:'ZHANWURENYUAN',stationCode:v}).then((res)=>{
      //   this.conductorPersonNames=res.data.data;
      // });
      // getPersonRole({roleCode:'ZBZZ',stationCode:v}).then((res)=>{
      //   this.conductorPersonNames=res.data.data;
      // });
      let lineCode=this.$store.getters.userInfo.lineCode;
      let stationCode=this.$store.getters.userInfo.stationCode;
      getSysUserToLS({lineCode:lineCode,stationCode:stationCode}).then(res=>{
        this.conductorPersonNames=res.data.data;
      })

    },
  },
  mounted() {
    this.changeStation();
  }
}
</script>
<style lang="scss">
.huLianWangShouPiaojiDataInput {
  height: 100%;

  &__tree {
    padding-top: 3px;
    padding-right: 20px;
  }

  &__main {
    .el-card__body {
      padding-top: 0;
    }
  }
  .avue-form__group{

  }
}
</style>
